import 'package:flutter/material.dart';
import 'package:wuliu01/TabBarPage/TabBarPage.dart';
import 'package:wuliu01/components/LoginPage.dart';
import 'package:wuliu01/components/Setting.dart';
import 'package:wuliu01/utils/token.dart';

void main() {
  runApp(
    MaterialApp(
      routes: {
        '/': (context) => const LoginPage(),
        '/detail': (context) => const Setting(),
        '/homePage': (context) => const Tabbarpage(),
        '/exit': (context) => const LoginPage(),
      },
      onGenerateRoute: (settings) {
        final tokenManager = TokenManager();
        final token = tokenManager.getToken() ?? '';
        if (token.isEmpty && settings.name != '/login') {
          return MaterialPageRoute(builder: (context) => const LoginPage());
        }

        return null;
      },
      initialRoute: '/',
    ),
  );
}
